﻿#if UNITY_EDITOR
using System.Collections.Generic;
using Ease.EaseNode.Runtime;

namespace Ease.EaseMission.Runtime
{
    public class MissionNodeInfoConverter : INodeInfoConverer<List<string>>
    {

        public List<string> ToInputData(List<PortInfo> input)
        {
            List<string> datas = new List<string>();
            foreach (var portName in input[0].portNames)
            {
                if (PortInfo.GetInfoFromPortName(portName, out var key, out var id))
                    datas.Add(key);
            }

            return datas;
        }

        public List<string> ToOutputData(List<PortInfo> output)
        {
            List<string> datas = new List<string>();
            foreach (var portName in output[0].portNames)
            {
                if (PortInfo.GetInfoFromPortName(portName, out var key, out var id))
                    datas.Add(key);
            }

            return datas;
        }

        public List<PortInfo> ToInputPortInfo(List<string> data, string key)
        {
            List<PortInfo> portInfos = new List<PortInfo>();
            var portInfo = new PortInfo();
            portInfo.portName = PortUtil.CreateName("input", key, 0);
            foreach (var s in data)
            {
                portInfo.portNames.Add(PortUtil.CreateName("output", s, 0));
            }

            portInfos.Add(portInfo);
            return portInfos;
        }

        public List<PortInfo> ToOutputPortInfo(List<string> data, string key)
        {
            List<PortInfo> portInfos = new List<PortInfo>();
            var portInfo = new PortInfo();
            portInfo.portName = PortUtil.CreateName("output", key, 0);
            foreach (var s in data)
            {
                portInfo.portNames.Add(PortUtil.CreateName("input", s, 0));
            }

            portInfos.Add(portInfo);
            return portInfos;
        }

    }
}
#endif